package com.szosen.xml;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

import android.text.TextUtils;
import android.util.Xml;

import com.szosen.application.MyApplication;
import com.szosen.database.AccessoryExamination;
import com.szosen.database.ChineseMedicineManage;
import com.szosen.database.Examination;
import com.szosen.database.HealthAssessment;
import com.szosen.database.HealthRecord;
import com.szosen.database.InhospitalSituation;
import com.szosen.database.LifestySituation;
import com.szosen.database.MedicineDesc;
import com.szosen.database.MedicineSituation;
import com.szosen.database.NonimmuneInoculation;
import com.szosen.database.OldPeopleSelfCare;
import com.szosen.database.Visit_info;
import com.szosen.database.Visit_info2;
import com.szosen.database.base_info;
import com.szosen.database.jwsjb;
import com.szosen.database.jwsss;
import com.szosen.database.jwssx;
import com.szosen.database.jwsws;
import com.szosen.jkzj.activity.BaseActivity;
import com.szosen.util.TimeHelper;

public class XmlTool {
	// 上传的测试账号
	// private static String guid = "445103001";
	// private static String docId = "fxlxl";
	private static String guid = MyApplication.getUserName();
	private static String docId = MyApplication.getPassword();
	private static String encoding = "UTF-8";

	public static String HealthRecordtoString(HealthRecord healthRecord) {
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			Field[] f;
			String name;
			String txt = "";
			serializer.setOutput(read);
			serializer.startDocument(encoding, null);
			serializer.startTag(null, "uploadinfo");
			serializer.attribute(null, "info", "EHR_HealthRecord");
			serializer.startTag(null, "manageInfo");
			serializer.startTag(null, "manageUnit");
			serializer.text(guid);// 机构代码：66666
			serializer.endTag(null, "manageUnit");
			serializer.startTag(null, "createUser");
			serializer.text(docId);// 医生账号：66666
			serializer.endTag(null, "createUser");
			serializer.endTag(null, "manageInfo");
			serializer.startTag(null, "HealthRecord");
			f = healthRecord.getClass().getDeclaredFields();
			// System.out.println("数组长度" + f.length);
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("jwssxs")||name.equals("time")|| name.equals("serialVersionUID")) {
					if (name.equals("jwsjbs")) {
						jwsjbListToString(healthRecord.getJwsjbs(), serializer,
								read);
					} else if (name.equals("jwssss")) {
						jwsssListToString(healthRecord.getJwssss(), serializer,
								read);
					} else if (name.equals("jwssxs")) {
						jwssxListToString(healthRecord.getJwssxs(), serializer,
								read);
					} else if (name.equals("jwswss")) {
						jwswsListToString(healthRecord.getJwswss(), serializer,
								read);
					}
				} else {
					try {
						serializer.startTag(null, name);
						txt = (String) field.get(healthRecord);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							// String newTxt = new String(txt.getBytes("gbk"),
							// encoding);
							// serializer.text(newTxt);
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("createTime")
									|| name.equals("birthday")) {
								serializer.text(txt + " " + "00:00:00");
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}
						serializer.endTag(null, name);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
						continue;
					}
				}
			}
			serializer.endTag(null, "HealthRecord");
			serializer.endTag(null, "uploadinfo");
			serializer.endDocument();
			serializer.flush();
			return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return read.toString();
	}

	// List<jwsjb> jwsjbs = new ArrayList<jwsjb>();// 既往史疾病
	// List<jwsss> jwssss = new ArrayList<jwsss>();// 既往史手术
	// List<jwsws> jwswss = new ArrayList<jwsws>();// 既往史外伤
	// List<jwssx> jwssxs = new ArrayList<jwssx>();// 既往史输血
	/***
	 * 将既往史的集合换成字符串。
	 *
	 * @param list
	 * @return
	 */
	public static String jwsjbListToString(List<jwsjb> list,
			XmlSerializer serializer, StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			jwsjb bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jwsupload2String(bean, serializer, read);
		}
		return sb.toString();
	}

	public static String jwsssListToString(List<jwsss> list,
			XmlSerializer serializer, StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			jwsss bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jwsupload2String(bean, serializer, read);
		}
		return sb.toString();
	}

	/***
	 * 高血压随访记录
	 *
	 * @param visit_info
	 * @return
	 */
	public static String GXY2String(Visit_info visit_info) {

		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			Field[] f;
			String name;
			String txt = "";
			serializer.setOutput(read);
			serializer.startDocument(encoding, null);
			serializer.startTag(null, "uploadinfo");
			serializer.attribute(null, "info", "MDC_HypertensionVisit");
			serializer.startTag(null, "manageInfo");
			serializer.startTag(null, "manageUnit");
			serializer.text(guid);// 机构代码：66666
			serializer.endTag(null, "manageUnit");
			serializer.startTag(null, "createUser");
			serializer.text(docId);// 医生账号：66666
			serializer.endTag(null, "createUser");
			serializer.endTag(null, "manageInfo");
			serializer.startTag(null, "Visit_info");
			serializer.attribute(null, "alias", "高血压随访记录");
			f = visit_info.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("jwssxs")
						|| name.equals("time") || name.equals("MedicineDescs")
						|| name.equals("xml")|| name.equals("serialVersionUID")) {
					if (name.equals("MedicineDescs")) {
						MedicineDescsListToString(
								visit_info.getMedicineDescs(), serializer, read);
					}
				} else {
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(visit_info);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("visitDate")||name.equals("nextDate")) {
								serializer.text(txt + " " + "00:00:00");
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, "Visit_info");
			serializer.endTag(null, "uploadinfo");
			serializer.endDocument();
			serializer.flush();
			return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return read.toString();
	}

	public static String MedicineDescsListToString(List<MedicineDesc> list,
			XmlSerializer serializer, StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			MedicineDesc bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			MedicineDescstoString(bean, serializer, read);
		}
		return sb.toString();
	}

	/***
	 * 获取保存的用药情况的xml
	 *
	 * @param InhospitalSituations
	 * @return
	 */
	public static String getMedicineDescsXml(List<MedicineDesc> MedicineDescs) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (MedicineDescs != null && MedicineDescs.size() > 0) {
				for (int i = 0; i < MedicineDescs.size(); i++) {
					MedicineDesc bean = MedicineDescs.get(i);
					System.out.println("输出用药情况情况:" + bean);
					if (bean != null) {
						MedicineDescstoString(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("高血压和糖尿病的用药情况转化xml结果：" + result);
		return result;
	}

	// 药物的列表转化
	private static void MedicineDescstoString(MedicineDesc bean,
			XmlSerializer serializer, StringWriter read) {
		// XmlSerializer serializer = Xml.newSerializer();
		// StringWriter read = new StringWriter();
		String className = bean.getClass().getSimpleName();
		try {
			Field[] f;
			String name;
			String txt = "";
			// serializer.setOutput(read);
			// serializer.startTag(null, "jwsjb");
			serializer.startTag(null, className);
			serializer.attribute(null, "alias", "用药情况");
			f = bean.getClass().getDeclaredFields();
			// System.out.println("数组长度" + f.length);
			for (Field field : f) {
				name = field.getName();
				// 如果是idCard就不需要
				if (!name.equals("time") && !name.equals("xml")) {
					// System.out.println("name" + name);
					field.setAccessible(true);
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(bean);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					if (null != txt) {
						if (txt.length() > 0 && txt.endsWith(",")) {
							String txt2 = txt.substring(0, txt.length() - 1);
							txt = txt2;
						}
						if (name.equals("inhospitalDate")
								|| name.equals("outhospitalDate")
								|| name.equals("inoculationDate")
								|| name.equals("useDate")
								|| name.equals("medicineUnit")) {
							// medicineUnit如果是单位。写mg
							serializer.text("01");
						} else {
							serializer.text(txt);
						}
					} else {
						if (name.equals("medicineUnit")) {
							// medicineUnit如果是单位。写mg
							serializer.text("01");
						} else {
							serializer.text("");
						}
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, className);
			// serializer.endDocument();
			// serializer.flush();
			// return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// System.out.println("读取的每个jws的内容" + read.toString());
		// return read.toString();
	}

	/***
	 * 通过xml的既往史xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<MedicineDesc> parseMedicineDescByxml(
			String MedicineDescsXml) {
		List<MedicineDesc> result = null;
		MedicineDesc bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(MedicineDescsXml)); // 设置输入流
																	// 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<MedicineDesc>();
					break;
				// <otherMedicineDesc>药物名称</otherMedicineDesc>
				// <medicineFrequency>次数</medicineFrequency>
				// <days>天数</days>
				// <medicineDosage>每次剂量</medicineDosage>
				// <medicineUnit>剂量单位</medicineUnit>
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("MedicineDesc")) {
						bean = new MedicineDesc();
					} else if (parser.getName().equals("otherMedicineDesc")) {
						eventType = parser.next();
						bean.setOtherMedicineDesc(parser.getText());
					} else if (parser.getName().equals("medicineFrequency")) {
						eventType = parser.next();
						bean.setMedicineFrequency(parser.getText());
					} else if (parser.getName().equals("days")) {
						eventType = parser.next();
						bean.setDays(parser.getText());
					} else if (parser.getName().equals("medicineDosage")) {
						eventType = parser.next();
						bean.setMedicineDosage(parser.getText());
					} else if (parser.getName().equals("medicineUnit")) {
						eventType = parser.next();
						bean.setMedicineUnit(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("MedicineDesc")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 高血压随访记录
	 *
	 * @param visit_info
	 * @return
	 */
	public static String TNB2String(Visit_info2 visit_info) {

		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			Field[] f;
			String name;
			String txt = "";
			serializer.setOutput(read);
			serializer.startDocument(encoding, null);
			serializer.startTag(null, "uploadinfo");
			serializer.attribute(null, "info", "MDC_DiabetesVisit");
			serializer.startTag(null, "manageInfo");
			serializer.startTag(null, "manageUnit");
			serializer.text(guid);// 机构代码：66666
			serializer.endTag(null, "manageUnit");
			serializer.startTag(null, "createUser");
			serializer.text(docId);// 医生账号：66666
			serializer.endTag(null, "createUser");
			serializer.endTag(null, "manageInfo");
			serializer.startTag(null, "Visit_info");
			serializer.attribute(null, "alias", "糖尿病随访记录");
			f = visit_info.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("jwssxs")
						|| name.equals("time") || name.equals("MedicineDescs")
						|| name.equals("xml")|| name.equals("serialVersionUID")) {
					if (name.equals("MedicineDescs")) {
						MedicineDescsListToString(
								visit_info.getMedicineDescs(), serializer, read);
					}

				} else {
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(visit_info);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("visitDate")||name.equals("nextDate")||name.equals("testDate")) {
								if(name.equals("testDate")){
									serializer.text(TimeHelper.getJKTJCheckTime() + " " + "00:00:00");
								}else{
									serializer.text(txt + " " + "00:00:00");
								}
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, "Visit_info");
			serializer.endTag(null, "uploadinfo");
			serializer.endDocument();
			serializer.flush();
			return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return read.toString();
	}

	/***
	 * 老年人自理能力
	 *
	 * @return
	 */
	public static String Lnrshzlnl2String(OldPeopleSelfCare old) {

		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			Field[] f;
			String name;
			String txt = "";
			serializer.setOutput(read);
			serializer.startDocument(encoding, null);
			serializer.startTag(null, "uploadinfo");
			serializer.attribute(null, "info", "MDC_OldPeopleSelfCare");
			serializer.startTag(null, "manageInfo");
			serializer.startTag(null, "manageUnit");
			serializer.text(guid);// 机构代码：66666
			serializer.endTag(null, "manageUnit");
			serializer.startTag(null, "createUser");
			serializer.text(docId);// 医生账号：66666
			serializer.endTag(null, "createUser");
			serializer.endTag(null, "manageInfo");
			serializer.startTag(null, "OldPeopleSelfCare");
			serializer.attribute(null, "alias", "老年人生活自理能力评估");
			f = old.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("jwssxs")
						|| name.equals("time")|| name.equals("serialVersionUID")) {
				} else {
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(old);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("inputDate")) {
								serializer.text(txt + " " + "00:00:00");
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, "OldPeopleSelfCare");
			serializer.endTag(null, "uploadinfo");
			serializer.endDocument();
			serializer.flush();
			return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return read.toString();

	}

	/***
	 * 老年人中医药管理
	 *
	 * @param manage
	 * @return
	 */
	public static String lnrzyygl2String(ChineseMedicineManage manage) {
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			Field[] f;
			String name;
			String txt = "";
			serializer.setOutput(read);
			serializer.startDocument(encoding, null);
			serializer.startTag(null, "uploadinfo");
			serializer.attribute(null, "info", "MDC_ChineseMedicineManage");
			serializer.startTag(null, "manageInfo");
			serializer.startTag(null, "manageUnit");
			serializer.text(guid);// 机构代码：66666
			serializer.endTag(null, "manageUnit");
			serializer.startTag(null, "createUser");
			serializer.text(docId);// 医生账号：66666
			serializer.endTag(null, "createUser");
			serializer.endTag(null, "manageInfo");
			serializer.startTag(null, "ChineseMedicineManage");
			serializer.attribute(null, "alias", "老年人中医药健康管理");
			f = manage.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("jwssxs")
						|| name.equals("time")|| name.equals("serialVersionUID")) {
				} else {
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(manage);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("reportDate")) {
								serializer.text(txt + " " + "00:00:00");
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, "ChineseMedicineManage");
			serializer.endTag(null, "uploadinfo");
			serializer.endDocument();
			serializer.flush();
			return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return read.toString();

	}

	public static String jwswsListToString(List<jwsws> list,
			XmlSerializer serializer, StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			jwsws bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jwsupload2String(bean, serializer, read);
		}
		return sb.toString();
	}

	public static String jwssxListToString(List<jwssx> list,
			XmlSerializer serializer, StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			jwssx bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jwsupload2String(bean, serializer, read);
		}
		return sb.toString();
	}

	//
	// serializer.startTag(null, "HealthRecord");
	// f = healthRecord.getClass().getDeclaredFields();
	// //System.out.println("数组长度" + f.length);
	// for (Field field : f) {
	// name = field.getName();
	// //System.out.println("name" + name);
	// field.setAccessible(true);
	// if (name.equals("jwsss") && name.equals("jwsws")
	// && name.equals("jwsjb") && name.equals("jwssx")) {
	//
	// } else {
	// serializer.startTag(null, name);
	// try {
	// txt = (String) field.get(healthRecord);
	// } catch (IllegalAccessException e) {
	// e.printStackTrace();
	// }
	// if (null != txt) { if (txt.length() > 0 && txt.endsWith(",")) {String
	// txt2 = txt.substring(0, txt.length() - 1);txt=txt2;}
	// serializer.text(txt);
	// }
	// serializer.endTag(null, name);
	// }
	// }
	// serializer.endTag(null, "HealthRecord");
	// serializer.endTag(null, "uploadinfo");
	// serializer.endDocument();
	// serializer.flush();
	// return read.toString();
	// } catch (IllegalArgumentException e) {
	// e.printStackTrace();
	// } catch (IllegalStateException e) {
	// e.printStackTrace();
	// } catch (IOException e) {
	// e.printStackTrace();
	// }
	// return read.toString();
	// }
	// List<jwsjb> jwsjbs = new ArrayList<jwsjb>();// 既往史疾病
	// List<jwsss> jwssss = new ArrayList<jwsss>();// 既往史手术
	// List<jwsws> jwswss = new ArrayList<jwsws>();// 既往史外伤
	// List<jwssx> jwssxs = new ArrayList<jwssx>();// 既往史输血

	public static synchronized void jwsupload2String(Object jwsjb,
			XmlSerializer serializer, StringWriter read) {
		// XmlSerializer serializer = Xml.newSerializer();
		// StringWriter read = new StringWriter();
		String className = jwsjb.getClass().getSimpleName();
		try {
			Field[] f;
			String name;
			String txt = "";
			// serializer.setOutput(read);
			// serializer.startTag(null, "jwsjb");
			serializer.startTag(null, className);
			if (!TextUtils.isEmpty(className)) {
				if ("jwsss".equals(className)) {
					serializer.attribute(null, "sscode", "060612");
				} else if ("jwsws".equals(className)) {
					serializer.attribute(null, "wscode", "040412");
				} else if ("jwssx".equals(className)) {
					serializer.attribute(null, "sxcode", "070712");
				}
			}
			f = jwsjb.getClass().getDeclaredFields();
			// System.out.println("数组长度" + f.length);
			for (Field field : f) {
				name = field.getName();
				// 如果是idCard就不需要
				if (!name.equals("idCard")) {
					// System.out.println("name" + name);
					field.setAccessible(true);
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(jwsjb);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					if (null != txt) {
						if (txt.length() > 0 && txt.endsWith(",")) {
							String txt2 = txt.substring(0, txt.length() - 1);
							txt = txt2;
						}
						if (name.equals("jwsjbqzsj")
								|| name.equals("jwsssqzsj")
								|| name.equals("jwswsqzsj")
								|| name.equals("jwssxqzsj")
								&& !TextUtils.isEmpty(txt)) {
							serializer.text(txt + " " + "00:00:00");
						} else {
							serializer.text(txt);
						}
					} else {
						serializer.text("");
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, className);
			// serializer.endDocument();
			// serializer.flush();
			// return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// System.out.println("读取的每个jws的内容" + read.toString());
		// return read.toString();
	}

	public static synchronized void jws2String(Object jwsjb,
			XmlSerializer serializer, StringWriter read) {
		// XmlSerializer serializer = Xml.newSerializer();
		// StringWriter read = new StringWriter();
		String className = jwsjb.getClass().getSimpleName();
		try {
			Field[] f;
			String name;
			String txt = "";
			// serializer.setOutput(read);
			// serializer.startTag(null, "jwsjb");
			serializer.startTag(null, className);
			f = jwsjb.getClass().getDeclaredFields();
			// System.out.println("数组长度" + f.length);
			for (Field field : f) {
				name = field.getName();
				// 如果是idCard就不需要
				if (!name.equals("idCard")) {
					// System.out.println("name" + name);
					field.setAccessible(true);
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(jwsjb);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
					if (null != txt) {
						if (txt.length() > 0 && txt.endsWith(",")) {
							String txt2 = txt.substring(0, txt.length() - 1);
							txt = txt2;
						}
						serializer.text(txt);
					} else {
						serializer.text("");
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, className);
			// serializer.endDocument();
			// serializer.flush();
			// return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// System.out.println("读取的每个jws的内容" + read.toString());
		// return read.toString();
	}

	/***
	 * 获取健康体检的上传的xml格式。
	 */
	public static String getJktj2String(base_info base, LifestySituation ls,
			Examination examin, AccessoryExamination a, InhospitalSituation i,
			MedicineSituation m, NonimmuneInoculation n, HealthAssessment h) {

		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			Field[] f;
			String name;
			String txt = "";
			serializer.setOutput(read);
			serializer.startDocument(encoding, null);
			serializer.startTag(null, "uploadinfo");
			serializer.attribute(null, "info", "hc_healthCheck");
			serializer.startTag(null, "manageInfo");
			serializer.startTag(null, "manageUnit");
			serializer.text(guid);// 机构代码：66666
			serializer.endTag(null, "manageUnit");
			serializer.startTag(null, "createUser");
			serializer.text(docId);// 医生账号：66666
			serializer.endTag(null, "createUser");
			serializer.endTag(null, "manageInfo");

			// /base_info
			serializer.startTag(null, "base_info");
			serializer.attribute(null, "alias", "基本情况");
			f = base.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("time")
						|| name.equals("InhospitalSituations")
						|| name.equals("MedicineSituations")
						|| name.equals("NonimmuneInoculations")) {
					if (name.equals("InhospitalSituations")) {
						InhospitalSituationsListToString(
								base.getInhospitalSituations(), serializer,
								read);
					} else if (name.equals("MedicineSituations")) {
						MedicineSituationsListToString(
								base.getMedicineSituations(), serializer, read);
					} else if (name.equals("NonimmuneInoculations")) {
						NonimmuneInoculationsListToString(
								base.getNonimmuneInoculations(), serializer,
								read);
					}

				} else {
					try {
						serializer.startTag(null, name);
						txt = (String) field.get(base);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("checkDate")) {
								serializer.text(txt + " " + "00:00:00");
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}
						serializer.endTag(null, name);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			}
			serializer.endTag(null, "base_info");

			// /LifestySituation生活方式
			serializer.startTag(null, "LifestySituation");
			serializer.attribute(null, "alias", "生活方式");
			f = ls.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("time")
						|| name.equals("InhospitalSituations")
						|| name.equals("MedicineSituations")
						|| name.equals("NonimmuneInoculations")) {
				} else {
					try {
						serializer.startTag(null, name);
						txt = (String) field.get(ls);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							if (name.equals("checkDate")) {
								serializer.text(txt + " " + "00:00:00");
							} else {
								serializer.text(txt);
							}
						} else {
							serializer.text("");
						}

						serializer.endTag(null, name);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			}
			serializer.endTag(null, "LifestySituation");

			// /Examination查体
			serializer.startTag(null, "Examination");
			serializer.attribute(null, "alias", "查体");
			f = examin.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("time")
						|| name.equals("InhospitalSituations")
						|| name.equals("MedicineSituations")
						|| name.equals("NonimmuneInoculations")) {
				} else {
					try {
						serializer.startTag(null, name);
						txt = (String) field.get(examin);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							serializer.text(txt);
						} else {
							serializer.text("");
						}
						serializer.endTag(null, name);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			}
			serializer.endTag(null, "Examination");

			// /AccessoryExamination辅助检查
			serializer.startTag(null, "AccessoryExamination");
			serializer.attribute(null, "alias", "辅助检查");
			f = a.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("time")
						|| name.equals("InhospitalSituations")
						|| name.equals("MedicineSituations")
						|| name.equals("NonimmuneInoculations")) {
				} else {
					try {
						serializer.startTag(null, name);
						txt = (String) field.get(a);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							serializer.text(txt);
						} else {
							serializer.text("");
						}
						serializer.endTag(null, name);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			}
			serializer.endTag(null, "AccessoryExamination");
			// 健康体检的先注释掉，这个不需要上传了。
			/*
			 * // /InhospitalSituation住院治疗情况 serializer.startTag(null,
			 * "InhospitalSituation"); serializer.attribute(null, "alias",
			 * "住院治疗情况"); f = base.getClass().getDeclaredFields(); for (Field
			 * field : f) { name = field.getName(); // System.out.println("name"
			 * + name); field.setAccessible(true); if (name.equals("jwsss") ||
			 * name.equals("jwsws") || name.equals("jwsjb") ||
			 * name.equals("jwssx") || name.equals("jwssss") ||
			 * name.equals("jwswss") || name.equals("jwsjbs") ||
			 * name.equals("time")|| name.equals("InhospitalSituations") ||
			 * name.equals("MedicineSituations") ||
			 * name.equals("NonimmuneInoculations")||name.equals("xml")) { }
			 * else { try { serializer.startTag(null, name); txt = (String)
			 * field.get(base); if (null != txt) { if (txt.length() > 0 &&
			 * txt.endsWith(",")) {String txt2 = txt.substring(0, txt.length() -
			 * 1);txt=txt2;} serializer.text(txt); } serializer.endTag(null,
			 * name); } catch (IllegalAccessException e) { e.printStackTrace();
			 * } } } serializer.endTag(null, "InhospitalSituation");
			 *
			 * // /MedicineSituation住院用药情况 serializer.startTag(null,
			 * "MedicineSituation"); serializer.attribute(null, "alias",
			 * "住院用药情况"); f = base.getClass().getDeclaredFields(); for (Field
			 * field : f) { name = field.getName(); // System.out.println("name"
			 * + name); field.setAccessible(true); if (name.equals("jwsss") ||
			 * name.equals("jwsws") || name.equals("jwsjb") ||
			 * name.equals("jwssx") || name.equals("jwssss") ||
			 * name.equals("jwswss") || name.equals("jwsjbs") ||
			 * name.equals("time")||name.equals("xml")) { } else { try {
			 * serializer.startTag(null, name); txt = (String) field.get(base);
			 * if (null != txt) { if (txt.length() > 0 && txt.endsWith(","))
			 * {String txt2 = txt.substring(0, txt.length() - 1);txt=txt2;}
			 * serializer.text(txt); } serializer.endTag(null, name); } catch
			 * (IllegalAccessException e) { e.printStackTrace(); } } }
			 * serializer.endTag(null, "MedicineSituation");
			 *
			 * // /NonimmuneInoculation非免疫规划预防接种 serializer.startTag(null,
			 * "NonimmuneInoculation"); serializer.attribute(null, "alias",
			 * "非免疫规划预防接种"); f = base.getClass().getDeclaredFields(); for (Field
			 * field : f) { name = field.getName(); // System.out.println("name"
			 * + name); field.setAccessible(true); if (name.equals("jwsss") ||
			 * name.equals("jwsws") || name.equals("jwsjb") ||
			 * name.equals("jwssx") || name.equals("jwssss") ||
			 * name.equals("jwswss") || name.equals("jwsjbs") ||
			 * name.equals("time")||name.equals("xml")) { } else { try {
			 * serializer.startTag(null, name); txt = (String) field.get(base);
			 * if (null != txt) { if (txt.length() > 0 && txt.endsWith(","))
			 * {String txt2 = txt.substring(0, txt.length() - 1);txt=txt2;}
			 * serializer.text(txt); } serializer.endTag(null, name); } catch
			 * (IllegalAccessException e) { e.printStackTrace(); } } }
			 * serializer.endTag(null, "NonimmuneInoculation");
			 */

			// /HealthAssessment健康评价表
			serializer.startTag(null, "HealthAssessment");
			serializer.attribute(null, "alias", "健康评价表");
			f = h.getClass().getDeclaredFields();
			for (Field field : f) {
				name = field.getName();
				// System.out.println("name" + name);
				field.setAccessible(true);
				if (name.equals("jwsss") || name.equals("jwsws")
						|| name.equals("jwsjb") || name.equals("jwssx")
						|| name.equals("jwssss") || name.equals("jwswss")
						|| name.equals("jwsjbs") || name.equals("time")|| name.equals("serialVersionUID")) {
				} else {
					try {
						serializer.startTag(null, name);
						txt = (String) field.get(h);
						if (null != txt) {
							if (txt.length() > 0 && txt.endsWith(",")) {
								String txt2 = txt
										.substring(0, txt.length() - 1);
								txt = txt2;
							}
							serializer.text(txt);
						} else {
							serializer.text("");
						}
						serializer.endTag(null, name);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			}
			serializer.endTag(null, "HealthAssessment");
			serializer.endTag(null, "uploadinfo");
			serializer.endDocument();
			serializer.flush();
			return read.toString();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return read.toString();
	}

	/***
	 * 通过xml的既往史xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<jwsjb> parsejwsjbByxml(String xml) {
		List<jwsjb> result = null;
		jwsjb bean = null;
		// XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		// XmlPullParser parser = factory.newPullParser();
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(xml)); // 设置输入流 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<jwsjb>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("jwsjb")) {
						bean = new jwsjb();
					} else if (parser.getName().equals("jwsjbcode")) {
						eventType = parser.next();
						bean.setJwsjbcode(parser.getText());
					} else if (parser.getName().equals("jwsjbmc")) {
						eventType = parser.next();
						bean.setJwsjbmc(parser.getText());
					} else if (parser.getName().equals("jwsjbqzsj")) {
						eventType = parser.next();
						bean.setJwsjbqzsj(parser.getText());
					} else if (parser.getName().equals("idCard")) {
						eventType = parser.next();
						bean.setIdCard(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("jwsjb")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 通过xml的既往史xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<jwsss> parsejwsssByxml(String xml) {
		List<jwsss> result = null;
		jwsss bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(xml)); // 设置输入流 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<jwsss>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("jwsss")) {
						bean = new jwsss();
					} else if (parser.getName().equals("jwsssmc")) {
						eventType = parser.next();
						bean.setJwsssmc(parser.getText());
					} else if (parser.getName().equals("jwsssqzsj")) {
						eventType = parser.next();
						bean.setJwsssqzsj(parser.getText());
					} else if (parser.getName().equals("idCard")) {
						eventType = parser.next();
						bean.setIdCard(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("jwsss")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 通过xml的既往史xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<jwsws> parsejwswsByxml(String xml) {
		List<jwsws> result = null;
		jwsws bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(xml)); // 设置输入流 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<jwsws>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("jwsws")) {
						bean = new jwsws();
					} else if (parser.getName().equals("jwswsmc")) {
						eventType = parser.next();
						bean.setJwswsmc(parser.getText());
					} else if (parser.getName().equals("jwswsqzsj")) {
						eventType = parser.next();
						bean.setJwswsqzsj(parser.getText());
					} else if (parser.getName().equals("idCard")) {
						eventType = parser.next();
						bean.setIdCard(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("jwsws")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 通过xml的既往史xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<jwssx> parsejwssxByxml(String xml) {
		List<jwssx> result = null;
		jwssx bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(xml)); // 设置输入流 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<jwssx>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("jwssx")) {
						bean = new jwssx();
					} else if (parser.getName().equals("jwssxyy")) {
						eventType = parser.next();
						bean.setJwssxyy(parser.getText());
					} else if (parser.getName().equals("jwssxqzsj")) {
						eventType = parser.next();
						bean.setJwssxqzsj(parser.getText());
					} else if (parser.getName().equals("idCard")) {
						eventType = parser.next();
						bean.setIdCard(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("jwssx")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 通过集合来返回xml字符串
	 *
	 * @param lists
	 * @return
	 */
	public static String getJwsjbXml(List<jwsjb> lists) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (lists != null && lists.size() > 0) {
				for (int i = 0; i < lists.size(); i++) {
					jwsjb bean = lists.get(i);
					System.out.println("bean:" + bean);
					if (bean != null) {
						jws2String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("既往史疾病结果：" + result);
		return result;
	}

	public static String getJwsssXml(List<jwsss> lists) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (lists != null && lists.size() > 0) {
				for (int i = 0; i < lists.size(); i++) {
					jwsss bean = lists.get(i);
					System.out.println("bean:" + bean);
					if (bean != null) {
						jws2String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("既往史手术结果：" + result);
		return result;
	}

	public static String getJwswsXml(List<jwsws> lists) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (lists != null && lists.size() > 0) {
				for (int i = 0; i < lists.size(); i++) {
					jwsws bean = lists.get(i);
					System.out.println("既往史外伤的bean:" + bean);
					if (bean != null) {
						jws2String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("既往史外伤结果：" + result);
		return result;
	}

	public static String getJwssxXml(List<jwssx> lists) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (lists != null && lists.size() > 0) {
				for (int i = 0; i < lists.size(); i++) {
					jwssx bean = lists.get(i);
					System.out.println("输血bean:" + bean);
					if (bean != null) {
						jws2String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("既往史输血结果：" + result);
		return result;
	}

	/***
	 * 获取住院治疗情况的xml
	 *
	 * @param InhospitalSituations
	 * @return
	 */
	public static String getInhospitalSituationXml(
			List<InhospitalSituation> InhospitalSituations) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (InhospitalSituations != null && InhospitalSituations.size() > 0) {
				for (int i = 0; i < InhospitalSituations.size(); i++) {
					InhospitalSituation bean = InhospitalSituations.get(i);
					System.out.println("输出住院治疗情况:" + bean);
					if (bean != null) {
						jktj32String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("住院治疗情况转化xml结果：" + result);
		return result;
	}

	/***
	 * 获取住院治疗情况的xml
	 *
	 * @param InhospitalSituations
	 * @return
	 */
	public static String getMedicineSituationXml(
			List<MedicineSituation> MedicineSituations) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (MedicineSituations != null && MedicineSituations.size() > 0) {
				for (int i = 0; i < MedicineSituations.size(); i++) {
					MedicineSituation bean = MedicineSituations.get(i);
					System.out.println("输出住院用药情况:" + bean);
					if (bean != null) {
						jktj32String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("住院用药情况转化xml结果：" + result);
		return result;
	}

	/***
	 * 非免疫。
	 *
	 * @param MedicineSituations
	 * @return
	 */
	public static String getNonimmuneInoculationXml(
			List<NonimmuneInoculation> NonimmuneInoculations) {
		String result = "";
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter read = new StringWriter();
		try {
			serializer.setOutput(read);
			if (NonimmuneInoculations != null
					&& NonimmuneInoculations.size() > 0) {
				for (int i = 0; i < NonimmuneInoculations.size(); i++) {
					NonimmuneInoculation bean = NonimmuneInoculations.get(i);
					System.out.println("输出非免疫情况:" + bean);
					if (bean != null) {
						jktj32String(bean, serializer, read);
						serializer.flush();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("读取信息出错");
			return "";
		}
		result = read.toString();
		System.out.println("非免疫情况转化xml结果：" + result);
		return result;
	}

	/***
	 * 健康体检的住院治疗情况、住院用药情况、非免疫3个转化
	 *
	 * @param jwsjb
	 * @param serializer
	 * @param read
	 */
	public static synchronized void jktjupload32String(Object jwsjb,
			XmlSerializer serializer, StringWriter read) {
		// XmlSerializer serializer = Xml.newSerializer();
		// StringWriter read = new StringWriter();
		String className = jwsjb.getClass().getSimpleName();
		try {
			Field[] f;
			String name;
			String txt = "";
			// serializer.setOutput(read);
			// serializer.startTag(null, "jwsjb");
			serializer.startTag(null, className);
			f = jwsjb.getClass().getDeclaredFields();
			// System.out.println("数组长度" + f.length);
			for (Field field : f) {
				name = field.getName();
				// 如果是idCard就不需要
				if (!name.equals("time") && !name.equals("xml")) {
					// System.out.println("name" + name);
					field.setAccessible(true);
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(jwsjb);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}

					if (null != txt) {
						if (txt.length() > 0 && txt.endsWith(",")) {
							String txt2 = txt.substring(0, txt.length() - 1);
							txt = txt2;
						}
						if (name.equals("inhospitalDate")
								|| name.equals("outhospitalDate")
								|| name.equals("inoculationDate")
								|| name.equals("useDate")) {
							serializer.text(txt + " " + "00:00:00");
						} else {
							serializer.text(txt);
						}
					} else {
						serializer.text("");
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, className);
			// serializer.endDocument();
			// serializer.flush();
			// return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// System.out.println("读取的每个jws的内容" + read.toString());
		// return read.toString();
	}

	/***
	 * 健康体检的住院治疗情况、住院用药情况、非免疫3个转化
	 *
	 * @param jwsjb
	 * @param serializer
	 * @param read
	 */
	public static synchronized void jktj32String(Object jwsjb,
			XmlSerializer serializer, StringWriter read) {
		// XmlSerializer serializer = Xml.newSerializer();
		// StringWriter read = new StringWriter();
		String className = jwsjb.getClass().getSimpleName();
		try {
			Field[] f;
			String name;
			String txt = "";
			// serializer.setOutput(read);
			// serializer.startTag(null, "jwsjb");
			serializer.startTag(null, className);
			f = jwsjb.getClass().getDeclaredFields();
			// System.out.println("数组长度" + f.length);
			for (Field field : f) {
				name = field.getName();
				// 如果是idCard就不需要
				if (!name.equals("time") && !name.equals("xml")) {
					// System.out.println("name" + name);
					field.setAccessible(true);
					serializer.startTag(null, name);
					try {
						txt = (String) field.get(jwsjb);
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}

					if (null != txt) {
						if (txt.length() > 0 && txt.endsWith(",")) {
							String txt2 = txt.substring(0, txt.length() - 1);
							txt = txt2;
						}
						serializer.text(txt);
					} else {
						serializer.text("");
					}
					serializer.endTag(null, name);
				}
			}
			serializer.endTag(null, className);
			// serializer.endDocument();
			// serializer.flush();
			// return read.toString();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// System.out.println("读取的每个jws的内容" + read.toString());
		// return read.toString();
	}

	/***
	 * 通过xml的住院治疗xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<InhospitalSituation> parseInhospitalSituationByxml(
			String xml) {
		List<InhospitalSituation> result = null;
		InhospitalSituation bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(xml)); // 设置输入流 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<InhospitalSituation>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("InhospitalSituation")) {
						bean = new InhospitalSituation();
					} else if (parser.getName().equals("type")) {
						eventType = parser.next();
						bean.setType(parser.getText());
					} else if (parser.getName().equals("inhospitalDate")) {
						eventType = parser.next();
						bean.setInhospitalDate(parser.getText());
					} else if (parser.getName().equals("outhospitalDate")) {
						eventType = parser.next();
						bean.setOuthospitalDate(parser.getText());
					} else if (parser.getName().equals("inhospitalReason")) {
						eventType = parser.next();
						bean.setInhospitalReason(parser.getText());
					} else if (parser.getName().equals(
							"medicalestablishmentName")) {
						eventType = parser.next();
						bean.setMedicalestablishmentName(parser.getText());
					} else if (parser.getName().equals("medicalrecordNumber")) {
						eventType = parser.next();
						bean.setMedicalrecordNumber(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("InhospitalSituation")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 通过xml的住院用药xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<MedicineSituation> parseMedicineSituationByxml(
			String MedicineSituationXml) {
		List<MedicineSituation> result = new ArrayList<MedicineSituation>();
		MedicineSituation bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(MedicineSituationXml)); // 设置输入流
																		// 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<MedicineSituation>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("MedicineSituation")) {
						bean = new MedicineSituation();
					} else if (parser.getName().equals("medicine")) {
						eventType = parser.next();
						bean.setMedicine(parser.getText());
					} else if (parser.getName().equals("use")) {
						eventType = parser.next();
						bean.setUse(parser.getText());
					} else if (parser.getName().equals("eachDose")) {
						eventType = parser.next();
						bean.setEachDose(parser.getText());
					} else if (parser.getName().equals("useDate")) {
						eventType = parser.next();
						bean.setUseDate(parser.getText());
					} else if (parser.getName().equals("medicineYield")) {
						eventType = parser.next();
						bean.setMedicineYield(parser.getText());
					} else if (parser.getName().equals("descr")) {
						eventType = parser.next();
						bean.setDescr(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("MedicineSituation")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/***
	 * 通过xml的非免疫xml来获取既往史疾病集合。
	 *
	 * @return
	 */
	public static List<NonimmuneInoculation> parseNonimmuneInoculationByxml(
			String NonimmuneInoculationXml) {
		List<NonimmuneInoculation> result = null;
		NonimmuneInoculation bean = null;
		try {
			XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
			parser.setInput(new StringReader(NonimmuneInoculationXml)); // 设置输入流
																		// 并指明编码方式
			int eventType;
			eventType = parser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				switch (eventType) {
				case XmlPullParser.START_DOCUMENT:
					result = new ArrayList<NonimmuneInoculation>();
					break;
				case XmlPullParser.START_TAG:
					if (parser.getName().equals("NonimmuneInoculation")) {
						bean = new NonimmuneInoculation();
					} else if (parser.getName().equals("name")) {
						eventType = parser.next();
						bean.setName(parser.getText());
					} else if (parser.getName().equals("inoculationDate")) {
						eventType = parser.next();
						bean.setInoculationDate(parser.getText());
					} else if (parser.getName().equals("inoculationUnit")) {
						eventType = parser.next();
						bean.setInoculationUnit(parser.getText());
					}
					break;
				case XmlPullParser.END_TAG:
					if (parser.getName().equals("NonimmuneInoculation")) {
						result.add(bean);
						bean = null;
					}
					break;
				}
				eventType = parser.next();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static String InhospitalSituationsListToString(
			List<InhospitalSituation> list, XmlSerializer serializer,
			StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			InhospitalSituation bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jktjupload32String(bean, serializer, read);
		}
		return sb.toString();
	}

	public static String MedicineSituationsListToString(
			List<MedicineSituation> list, XmlSerializer serializer,
			StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			MedicineSituation bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jktjupload32String(bean, serializer, read);
		}
		return sb.toString();
	}

	public static String NonimmuneInoculationsListToString(
			List<NonimmuneInoculation> list, XmlSerializer serializer,
			StringWriter read) {
		if (list == null) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < list.size(); i++) {
			NonimmuneInoculation bean = list.get(i);
			// sb.append(jws2String(bean, serializer, read));
			jktjupload32String(bean, serializer, read);
		}
		return sb.toString();
	}

}
